# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=fluent-bit
pkgver=2.1.10
pkgrel=0
pkgdesc="Fast and Lightweight Log processor and forwarder"
url="https://fluentbit.io/"
# riscv64: does not support bundled luajit
# arm: doesn't build
arch="all !armhf !armv7 !ppc64le !s390x !riscv64"
license="Apache-2.0"
# XXX:
# wamr, sqlite, rdkafka, c-ares, luajit are bundled
makedepends="
	bison
	cmake
	flex
	gtest-dev
	linux-headers
	musl-fts-dev
	openssl-dev
	yaml-dev
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-openrc
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/fluent/fluent-bit/archive/v$pkgver.tar.gz
	fluent-bit.initd
	chunkio-static-lib-fts.patch
	exclude-luajit.patch
	xsi-strerror.patch
	"
# enable check when this solved - https://github.com/fluent/fluent-bit/issues/2464#issuecomment-673280055
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	# default CORE_STACK_SIZE=((3 * PTHREAD_STACK_MIN) / 2)=3072 is invalid
	# based on https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/configuration-file
	# set default to 24576
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DFLB_CORO_STACK_SIZE=24576 \
		-DFLB_TESTS_INTERNAL=Yes \
		-DFLB_TLS=Yes \
		-DFLB_HTTP_SERVER=Yes \
		$CMAKE_CROSSOPTS .
	make -C build
}

check() {
	CTEST_OUTPUT_ON_FAILURE=1 make -C build test
}

package() {
	make -C build DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname

	mv "$pkgdir"/usr/etc/* "$pkgdir"/etc
}

sha512sums="
55caefa81cdeaf293b727829383c6eaa75bc2f8b8c61ebe15e1478c66033921fde6e50c39fc8c39a7d2d93d03892f709daf4d1b6caacf586133de5268de10299  fluent-bit-2.1.10.tar.gz
e17c8b7d09b524855167baf3a3766c5420181370cdd1d21133e7c18d7316b224a6c0aa240be26d3d0443d91247a82759161f7ad12f142b4b84924da5694a61e6  fluent-bit.initd
6bd7d8b4da93a17f29b6ea1e0286ea226d0e376024284741110936779b3229bd8d6cd03ffbdc5d3b4842294e7f32a888de0dd16b0851b65d91b062ca58530ea0  chunkio-static-lib-fts.patch
e3308a8377fb8ba496415b7a31e9e022e5aa9965d27a0c33ea5166a29049b72cb364bbcdf9d8611ef3407b0968f9bd4adff12cdb39728bbebd382710e5bc75d0  exclude-luajit.patch
d61f30344af997f126486fa5b34cd3fbfe88bfc9aea394a8c60d0206f4db8db998eadf637a3a581b89512411c1e7980c414e236e455d5e2b889d20a556ee6577  xsi-strerror.patch
"
